<?php
/**
 * Created by PhpStorm.
 * User: Dean.Wu
 * Date: 2018/3/05 0024
 * Time: 15:20
 */
namespace App\Http\Controllers\Admin;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class LoginController extends Controller{
    /**
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     * @name 登录页面
     * @author wudean
     */
     public function index(){
        return view('admin.login.index');
     }

    /**
     * @param Request $request
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
     * @name 登录操作
     */
     public function login(Request $request){
         $this->validate($request, [
             'name' => 'required|min:2',
             'password' => 'required|min:6|max:30',
         ]);
         $user = request(['name', 'password']);
         if (true == Auth::guard('admin')->attempt($user)) {
             return redirect('/admin/index');
         }

         return \Redirect::back()->withErrors("用户名密码错误");
     }

    /**
     * @param Request $request
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
     * @name 退出登录
     */
     public function logout(Request $request){
         Auth::guard('admin')->logout();
         return redirect('/admin/login');
     }
}